package com.xiaohe66.web.gateway.http.sec;

import com.xiaohe66.common.value.R;
import com.xiaohe66.web.application.sys.sec.SecEncryptLoginAppService;
import com.xiaohe66.web.application.sys.sec.bo.SecEncryptLoginBo;
import com.xiaohe66.web.application.sys.sec.bo.SecSecretKeyChangeBo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author He
 * @since 2023.12.27 15:31
 */
@RestController
@RequestMapping("/sec/encrypt")
@Slf4j
@RequiredArgsConstructor
public class SecEncryptLoginController {

    private final SecEncryptLoginAppService encryptLoginAppService;

    @PostMapping("/login")
    public R<String> login(@RequestBody SecEncryptLoginBo bo) {

        return R.ok(encryptLoginAppService.login(bo));
    }

    @PutMapping("/change")
    public R<Void> change(@RequestBody SecSecretKeyChangeBo bo) {

        encryptLoginAppService.changePublicKey(bo);

        return R.ok();
    }

    @GetMapping("/serverpublickey")
    public R<String> serverPublicKey() {

        return R.ok(encryptLoginAppService.getServerPublicKey());
    }

}
